package cn.wolfcode.ssm.qo;

import lombok.Getter;
import lombok.Setter;

import java.util.List;
@Getter
@Setter
public class PageResult<T> {
    private int currentPage;
    private int pageSIze;
    private List<T> result;
    private int rows;
    private int totalPage;
    private int prevPage;
    private int nextPage;

    public  PageResult(int currentPage,int pageSIze,List<T> result,int rows){
        this.currentPage=currentPage;
        this.pageSIze=pageSIze;
        this.result=result;
        this.rows=rows;

        //查询条数不足一页时,全都设为1,currentPage已经设过了
        if(rows <=pageSIze){
            this.totalPage=1;
            this.prevPage=1;
            this.nextPage=1;
            return;//结束执行流程,不会在执行下去
        }

        this.totalPage= rows % pageSIze ==0? rows/pageSIze :rows/pageSIze+1;
        this.prevPage=currentPage-1>0 ? currentPage-1:1;
        this.nextPage=currentPage+1<totalPage? currentPage+1:totalPage;
    }
}
